package cn.mcartoon.smsdemo.controller;

import cn.mcartoon.smsdemo.utils.MathUtils;
import cn.mcartoon.smsdemo.utils.sms.SendSms;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 短信控制器
 */
@RestController
@RequestMapping("/sms")
public class SmsController {

    Logger log = LoggerFactory.getLogger(SmsController.class);

    @Autowired
    private SendSms sendSms;

    /**
     * 发送短信
     * @param phone
     * @return
     */
    @PostMapping("/send")
    public void verifyCode(String phone) throws Exception {
        log.info("发送短信phone：{}", phone);
        String sendCode = MathUtils.random();
        log.info("发送短信phone:{},验证码：{}" , phone, sendCode);
        String msgResult = sendSms.send(phone, sendCode);
    }

}
